package com.example.webchar.webchar.mapper.slave;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.webchar.webchar.pojo.Novel;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @program: wechat-web-is-my
 * @description
 * @author: 郭逍
 * @create: 2021/8/21 10:57
 **/
@Mapper
@Service
public interface NovelSlave extends BaseMapper<Novel> {
    /**
     * 查询所有的小说
     *
     * @return
     */
    @Select("SELECT id,update_location,novel_name FROM novel")
    List<Novel> selNovelName();

    /**
     * 模糊查询小说的名称或者是作者名称
     *
     * @param bookName
     * @return
     */
    @Select(" SELECT * FROM novel WHERE  novel_name LIKE #{bookName} or name Like #{bookName} ")
    List<Novel> fuzzyQueryNovel(@Param("bookName") String bookName);

    /**
     * 根据小说的类型查找小说
     *
     * @param type
     * @return
     */
    @Select("select * from novel where type=#{type}")
    List<Novel> queryNovelType(@Param("type") Integer type);

    /**
     * 根据指定的id查询当前小说的主要信息
     *
     * @param id
     * @return
     */
    @Select("select * from novel where id=#{id}")
    List<Novel> quereyNovelById(@Param("id") Integer id);

    /**
     * 查询最新创建的30本小说
     *
     * @return
     */
    @Select("select * from novel ORDER BY create_time DESC limit 0,30")
    List<Novel> quereyNovelByCreateTimeDesc();

    /**
     * 查询最新更改的最新30本小说
     *
     * @return
     */
    @Select("select * from novel ORDER BY update_time DESC limit 0,30")
    List<Novel> queryNovelByUpdateTimeDesc();

    /**
     * 根据不同的type属性 查询11本小说
     *
     * @param type
     * @return
     */
    @Select("select * from novel where type=#{type} limit 0,11")
    List<Novel> queryNovelTypeLimit(@Param("type") Integer type);

    /**
     * 根据作者的名称查询该作者的所有小说
     *
     * @param name
     * @return
     */
    @Select("select * from novel where name=#{name}")
    List<Novel> queryNovelByName(@Param("name") String name);
}
